
package com.hexinfo.dmpro.dev.data.transfer.service.impl;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hexinfo.dmpro.common.base.PageResult;
import com.hexinfo.dmpro.common.utils.CommonConstants;
import com.hexinfo.dmpro.dev.data.transfer.model.DesensitizeFunctionConf;
import com.hexinfo.dmpro.dev.data.transfer.dao.DesensitizeFunctionConfMapper;
import com.hexinfo.dmpro.dev.data.transfer.service.IDesensitizeFieldListService;
import com.hexinfo.dmpro.dev.data.transfer.service.IDesensitizeFieldMapService;
import com.hexinfo.dmpro.dev.data.transfer.service.IDesensitizeFunctionConfService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 脱敏函数配置表
 *
 * @author yyh.huang
 * @date 2023-09-19 18:37:08
 */
@Service
@AllArgsConstructor
public class DesensitizeFunctionConfServiceImpl extends ServiceImpl<DesensitizeFunctionConfMapper, DesensitizeFunctionConf> implements IDesensitizeFunctionConfService {

    private final IDesensitizeFieldListService desensitizeFieldListService;

    private final IDesensitizeFieldMapService desensitizeFieldMapService;

    @Override
    public PageResult queryList(Page page, DesensitizeFunctionConf desensitizeFunctionConf) {
        LambdaQueryWrapper<DesensitizeFunctionConf> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(DesensitizeFunctionConf::getDel,CommonConstants.STATUS_NORMAL);
        if (!StrUtil.isEmpty(desensitizeFunctionConf.getFunctionName())){
            wrapper.like(DesensitizeFunctionConf::getFunctionName,desensitizeFunctionConf.getFunctionName());
        }
        if (!StrUtil.isEmpty(desensitizeFunctionConf.getFunctionExplain())){
            wrapper.like(DesensitizeFunctionConf::getFunctionExplain,desensitizeFunctionConf.getFunctionExplain());
        }
        Page returnPage = this.baseMapper.selectPage(page, wrapper);
        return new PageResult(returnPage.getRecords(),returnPage.getTotal());
    }

    @Override
    public List<DesensitizeFunctionConf> queryListNoPage(DesensitizeFunctionConf desensitizeFunctionConf) {
        LambdaQueryWrapper<DesensitizeFunctionConf> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(DesensitizeFunctionConf::getDel,CommonConstants.STATUS_NORMAL);
        if (!StrUtil.isEmpty(desensitizeFunctionConf.getFunctionName())){
            wrapper.like(DesensitizeFunctionConf::getFunctionName,desensitizeFunctionConf.getFunctionName());
        }
        if (!StrUtil.isEmpty(desensitizeFunctionConf.getFunctionExplain())){
            wrapper.like(DesensitizeFunctionConf::getFunctionExplain,desensitizeFunctionConf.getFunctionExplain());
        }
        return this.baseMapper.selectList(wrapper);
    }

    /**
     * @Method removeByIds
     * @Param ids
     * @Return boolean
     * @Description 删除脱敏函数配置表
     * @Author Yin.Yang
     * @Date 2023/12/28 14:18
     * @Version V1.0
     */
    @Override
    @Transactional
    public boolean removeByIds(List<String> ids) {
        desensitizeFieldMapService.removeByFunctionIds(ids);
        ids.forEach(this::removeById);
        return true;
    }

}
